package com.springmvc.controller;

import com.springmvc.entity.Goods;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;

@Controller
public class IndexController {

    @RequestMapping("/rest/get/{id}/{userName}")
    public String rest_get(@PathVariable("id")Long id,@PathVariable("userName")String userName){
        System.out.println("id = " + id);
        System.out.println("userName = " + userName);
        return "rest";
    }

    @RequestMapping("/rest/post/{id}/{userName}")
    public String rest_post(@PathVariable("id")Long id,@PathVariable("userName")String userName){
        System.out.println("id = " + id);
        System.out.println("userName = " + userName);
        return "rest";
    }

    @RequestMapping("/doRest")
    public String toRest(){
        return "toRest";
    }

    @RequestMapping(value = "/rest/put/{id}/{userName}",method = RequestMethod.PUT)
    public String rest_put(@PathVariable("id")Long id,@PathVariable("userName")String userName,String password){
        System.out.println("id = " + id);
        System.out.println("userName = " + userName);
        System.out.println("password = " + password);
        return "rest";
    }

    @RequestMapping(value = "/rest/delete/{id}/{userName}",method = RequestMethod.DELETE)
    public String rest_delete(@PathVariable("id")Long id,@PathVariable("userName")String userName){
        System.out.println("id = " + id);
        System.out.println("userName = " + userName);
        return "rest";
    }


    @RequestMapping(value = "/rest/ajax/put/{id}/{userName}",method = RequestMethod.PUT)
    @ResponseBody
    public String rest_ajax_put(
            @PathVariable("id")Long id,
            @PathVariable("userName")String userName,
            @RequestBody Goods goods){
        System.out.println("id = " + id);
        System.out.println("userName = " + userName);
        System.out.println("goods = " + goods);
        return "success";
    }
}
